home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 16 / AMIGAplus Sonderheft 16 (1998)(ICP)(DE)[!].iso / pd / anwendungen / xpk_source / libraries / nuke / xpknuke.c < prev   
C/C++ Source or Header  |  1998-08-27  |  4KB  |  181 lines

  1. /*
  2.  * This library is mainly intended to demonstrate how to program a sub
  3.  * library.
  4.  */
  5.  
  6. #include <xpk/xpksub.h>
  7. #include <exec/memory.h>
  8. #include <proto/exec.h>
  9.  
  10. #define SDI_TO_ANSI
  11. #include "SDI_ASM_STD_protos.h"
  12.  
  13. #define SCANBUFLEN 32768
  14.  
  15. #define SysBase (*((struct ExecBase **) 4));
  16.  
  17. /*
  18.  * Pack a chunk
  19.  */
  20.  
  21. struct NukeData {
  22.     APTR    inbuf;
  23.     APTR    outbuf;
  24.     APTR    last;
  25.     APTR    next;
  26.     ULONG    cwri;
  27.     ULONG    uwri;
  28.     ULONG    uend;
  29.     ULONG    delpos;
  30.     UWORD    ulen;
  31.     UWORD    clen;
  32.     UWORD    ustop;
  33.     UWORD    ustart;
  34.     UWORD    ucount;
  35.     UWORD    scanrange;
  36.     UWORD    room1;
  37.     UWORD    room2;
  38.     UWORD    room4;
  39.     UWORD    roomN;
  40.     UWORD    data1;
  41.     UWORD    data2;
  42.     ULONG    data4;
  43.     ULONG    dataN;
  44.     ULONG    dest1;
  45.     ULONG    dest2;
  46.     ULONG    dest4;
  47.     ULONG    destN;
  48.     ULONG    dummy;
  49.     ULONG    contbuf;
  50.     ULONG    flags;
  51. };
  52.  
  53. #ifdef __cplusplus
  54. extern "C" {
  55. #endif
  56.  
  57. LONG   __asm AsmPack  (register __a4 struct NukeData *ND);
  58. STRPTR __asm AsmUnpack(register __a1 STRPTR wread, register __a4 STRPTR bread,
  59.                         register __a0 STRPTR dst, register __a2 STRPTR end);
  60. #ifdef __cplusplus
  61. }
  62. #endif
  63.  
  64. #define PACKMEM   (65536+SCANBUFLEN)*sizeof(UWORD)+sizeof(struct NukeData)
  65.  
  66. static struct XpkMode NukeMode = {
  67.   NULL,       // Next mode
  68.   100,        // Handles up to
  69.   XPKMF_A3000SPEED,      // Flags
  70.   PACKMEM,    // Packing memory
  71.   0,          // Unpacking memory
  72.   36,         // Packing speed
  73.   630,        // Unpacking speed
  74.   454,        // Compression ratio
  75.   0,          // Reserved
  76.   "normal",   // Description
  77. };
  78.  
  79. static struct XpkInfo NukeInfo = {
  80.     1,               /* info version */
  81.     1,               /* lib  version */
  82.     0,               /* master vers  */
  83.     1,               /* ModesVersion */
  84.     "NUKE"  ,        /* short name   */
  85.     "Nuke",          /* long name    */
  86.     "A relatively efficient packer that unpacks very quickly", /* Description */
  87.     0x4E554B45,    /* 'NUKE', 4 letter ID  */
  88.     XPKIF_PK_CHUNK | /* flags        */
  89.     XPKIF_UP_CHUNK,
  90.     30000,           /* max in chunk */
  91.     10,              /* min in chunk */
  92.     30000,           /* def in chunk */
  93.     "Nuking",        /* pk message   */
  94.     "Unnuking",      /* up message   */
  95.     "Nuked",         /* pk past msg  */
  96.     "Unnuked",       /* up past msg  */
  97.     50,              /* DefMode      */
  98.     0,               /* Pad          */
  99.     &NukeMode,       /* ModeDesc     */
  100.     0,               /* MinModeDesc  */
  101.     0,               /* MaxModeDesc  */
  102.     {0}              /* reserved     */
  103. };
  104.  
  105.  
  106. /*
  107.  * Returns an info structure about our packer
  108.  */
  109.  
  110. struct XpkInfo * __asm XpksPackerInfo(void)
  111. {
  112.     return &NukeInfo;
  113. }
  114.  
  115. #define LASTSIZE    (65536*sizeof(UWORD))
  116. #define NEXTSIZE    (SCANBUFLEN*sizeof(UWORD))
  117.  
  118. void __asm XpksPackFree(register __a0 struct XpkSubParams *xpar)
  119. {
  120.   struct NukeData *ND=(struct NukeData *)xpar->xsp_Sub[0];
  121.  
  122.   if(ND)
  123.   {
  124.     if(ND->last) FreeMem(ND->last, LASTSIZE);
  125.     if(ND->next) FreeMem(ND->next, NEXTSIZE);
  126.     FreeMem(ND, sizeof(struct NukeData));
  127.     xpar->xsp_Sub[0] = 0;
  128.   }
  129. }
  130.  
  131. struct NukeData *alloctabs(struct XpkSubParams *xpar)
  132. {
  133.   struct NukeData *ND;
  134.  
  135.   if((xpar->xsp_Sub[0] = (LONG) (ND = (struct NukeData *) AllocMem(sizeof(struct NukeData),MEMF_CLEAR))) &&
  136.       (ND->last = AllocMem(LASTSIZE,0)) &&
  137.       (ND->next = AllocMem(NEXTSIZE,0)))
  138.     return ND;
  139.   else
  140.   {
  141.     XpksPackFree(xpar);
  142.     return 0;
  143.   }
  144. }
  145.  
  146. LONG __asm XpksPackChunk(register __a0 struct XpkSubParams *xpar)
  147. {
  148.   struct NukeData *ND = (struct NukeData *)xpar->xsp_Sub[0];
  149.  
  150.   if(!ND)
  151.     if(!(ND=alloctabs(xpar)))
  152.       return XPKERR_NOMEM;
  153.  
  154.   ND->inbuf = xpar->xsp_InBuf;
  155.   ND->outbuf= xpar->xsp_OutBuf;
  156.   ND->ulen  = xpar->xsp_InLen;
  157.   ND->clen  = xpar->xsp_OutBufLen-4;
  158.  
  159.   memset(ND->last,0,LASTSIZE);
  160.   memset(ND->next,0,NEXTSIZE);
  161.  
  162.   if(((LONG)(xpar->xsp_OutLen = AsmPack(ND)))<0 || xpar->xsp_OutLen>xpar->xsp_InLen)
  163.     return XPKERR_EXPANSION;
  164.   return 0;
  165. }
  166.  
  167. LONG __asm XpksUnpackChunk(register __a0 struct XpkSubParams *xpar)
  168. {
  169. //  APTR end;
  170.  
  171. //  end=
  172.   AsmUnpack(xpar->xsp_InBuf, (STRPTR)xpar->xsp_InBuf  + xpar->xsp_InLen,
  173.             xpar->xsp_OutBuf, (STRPTR)xpar->xsp_OutBuf + xpar->xsp_OutLen);
  174.  
  175. //  if( xpar->xsp_OutBuf+xpar->xsp_OutLen != end )
  176. //    return XPKERR_CORRUPTPKD;
  177.  
  178.   return 0;
  179. }
  180.  
  181.